home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 3 / Cream of the Crop 3.iso / clipper / ks94an.zip / CHECKSUM.HDR < prev    next >
Text File  |  1994-04-25  |  3KB  |  109 lines

  1. /******************************************************************************
  2.                  The Klipper Library, for CA-Clipper 5.x
  3.         Copyright (c), 1994, Wallace Information Systems Engineering
  4.  
  5. FUNCTION:
  6.  
  7. _CheckSum( cString, nMode ) --> xRetVal
  8.  
  9. PARAMETERS:
  10.  
  11. cString : The string to be checksummed
  12. nMode   : Operation Mode:
  13.             KCRC_GENERATE = Generate checksum string
  14.             KCRC_TEST     = Test checksum string
  15.             KCRC_EXTRACT  = Extract checksum from string
  16.  
  17. SHORT:
  18.  
  19. _CheckSum() is a checksum generation and testing function.
  20.  
  21. DESCRIPTION:
  22.  
  23. KCRC_GENERATE MODE  (default mode)
  24. ----------------------------------
  25.  
  26.  
  27. In mode K_GEN, the string passed in cString is CRC'ed, the checksum digits
  28. are embedded in the string, and the new string is returned.
  29.  
  30. KCRC_TEST MODE
  31. --------------
  32.  
  33. In mode K_TST, the string passed in cString must have been generated
  34. by _CheckSum() in K_GEN mode.  The string is tested to see if it's checksum
  35. is valid.  A checksum is valid when it is ZERO.
  36.  
  37. KCRC_EXTRACT MODE
  38. -----------------
  39.  
  40. In KCRC_EXTRACT mode, cString must be a string created with _CheckSum()
  41. in KCFC_GENERATE Mode.  The checksum digits that were generated for the
  42. string are extracted from it and returned as a hexadecimal string.
  43.  
  44. Usage
  45. ----------
  46.  
  47.  
  48. The basic "modus operandi" is to generate a CRC'ed string using:
  49.  
  50. cStr1 = _CheckSum(cStr1,KCRC_GENERATE)
  51.  
  52. Then send it, transmit it, store and retrieve it, etc.
  53.  
  54. Then to verify that it has not changed during any operation, check it with:
  55.  
  56. nSameOrDiff = _CheckSum(cStr1,KCRC_TEST)
  57.  
  58. nSameOrDiff will be ZERO if the string has not changed any since it
  59. was CRC'ed, or non-ZERO if it has.
  60.  
  61. NOTE:
  62.  
  63. _CheckSum() returns values of different types depending upon usage mode.
  64.  
  65. This checksum is a loose interpretation of the Fletcher CRC algorithm.
  66. Fletcher's CRC, while not a full blown CRC is accurate with strings (blocks)
  67. up to 255 bytes. You should break your data into chunks of 255 bytes if it
  68. exceeds this amount, and CRC each block independantly. Theoretically, any
  69. block size will reliably produce a valid CRC value, *BUT* you should be aware
  70. of a few things.
  71.  
  72. Lot's of things will equate to the same checksum.  However, two strings under
  73. 2048 bytes, that are supposed to be the same in the first place, have a very
  74. very small chance of generating the same checksum.
  75.  
  76.  
  77. For instance a string of 63 of any one character and 318 of the same
  78. character will generate the same checksum.  However, it should be obvious,
  79. when looking for single bit or byte differences, that a 63 character string
  80. is not anything like a 318 character string, not matter what character they
  81. have in common, or how many of them.  LEN() used in conjunction with with the
  82. CRC should greatly increase security.
  83.  
  84.  
  85.  
  86.  
  87. EXAMPLE:
  88.  
  89. cString = "Mary had a little jam, it's beat was white and slow..."
  90.  
  91. // create the string with checksum digits
  92. cString = _Checksum(cString,KCRC_GENERATE) // cString has checksum
  93. // embedded now.
  94.  
  95.  
  96. // later, check to see if it is intact (ie, the same)
  97. nCRCResult = _CheckSum(cString,KCRC_TEST)  // nCRCResult has 0
  98. // if the string is
  99. // unchanged.
  100.  
  101.  
  102. // To see what the checksum value actually is:
  103. cCRCDigits = _CheckSum(cString,KCRC_EXTRACT)
  104.  
  105.  
  106. ? cCRCDigits  // Result "A61F" - Uhhhh, or something like that.
  107.  
  108. ******************************************************************************/
  109.